package com.controller;

import com.biz.IDiscussBiz;
import com.entity.Discuss;
import com.util.PageBean;
import com.util.QueryDiscuss;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/discuss")
public class DiscussAction {

    @Autowired
    private IDiscussBiz biz;

    public IDiscussBiz getBiz() {
        return biz;
    }

    public void setBiz(IDiscussBiz biz) {
        this.biz = biz;
    }

    //列表评论
    @RequestMapping("/list")
    public String getAll(HttpSession session)
    {
        List<Discuss> list= biz.getAll();
        session.setAttribute("dlist",list);
        return "/back/discuss_list";
    }

    //增加评论
    @RequestMapping("/add")
    public String add(Discuss dd)
    {
        biz.add_discuss(dd);
        return "back/discuss_list";
    }

    //删除评论
    @RequestMapping("/del")
    public String del(int id)
    {
        biz.del_discuss(id);
        return "redirect:list.action";
    }

    //根据id 查询评论内容
    @RequestMapping("/getbyid")
    public ModelAndView getById(int id)
    {
        Discuss dd=new Discuss();
        ModelAndView mv=new ModelAndView();
        mv.addObject("d",dd);
        mv.setViewName("/back/discuss_mod");
        return mv;
    }

    //修改评论内容
    @RequestMapping("/mod")
    public String mod(Discuss dd)
    {
        biz.mod_discuss(dd);
        return "/back/discuss_list";
    }

   //评论列表分页展示(分页+不定项)
   /* public PageBean get_page(@RequestParam(defaultValue="1")int page, QueryDiscuss qd,HttpSession session)
    {
        PageBean bean=biz.getPage_discuss(page, qd);
        session.setAttribute("pb",bean);
        return bean;
    }*/

    /**
     * 根据图书Id查询一组评论
     */
    @RequestMapping("/getDiscussByBid")
    @ResponseBody
    public List<Map> getByBid(Integer bid){
        List<Map> list=biz.getByBid(bid);
        return list;
    }

}
